package com.atguigu.cloud.controller;

import cn.hutool.core.date.DateUtil;
import com.atguigu.cloud.apis.PayFeignApi;
import com.atguigu.cloud.entities.PayDTO;
import com.atguigu.cloud.resp.ResultData;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class OrderController {
	
	@Resource
	private PayFeignApi payFeignApi;
	
	@GetMapping("/feign/pay/add")
	public ResultData addOrder(PayDTO payDTO) {
		System.out.println("第一步：模拟本地addOrder新增订单成功(省略sql操作)，第二步：再开启addPay支付微服务远程调用");
		ResultData resultData = payFeignApi.addPay(payDTO);
		return resultData;
	}
	
	@GetMapping("/feign/pay/get/{id}")
	public ResultData getPayInfo(@PathVariable("id") Integer id) {
		System.out.println("-------支付微服务远程调用，按照id查询订单支付流水信息");
		ResultData resultData = null;
		try {
			log.info("调用开始 == " + DateUtil.now());
			resultData = payFeignApi.getPayInfo(id);
		} catch (Exception e) {
			log.info("处理失败 == " + e.getMessage());
			log.info("调用结束 == " + DateUtil.now());
		}
		return resultData;
	}
	
	/**
	 * openfeign天然支持负载均衡演示
	 */
	@GetMapping(value = "/feign/pay/mylb")
	public String mylb()
	{
		return payFeignApi.mylb();
	}
	
	
}